﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace Jemgine.EffectEditor
{
    public partial class TexturePreview : GraphicsDeviceControl
    {
        private Jemgine.Engine.EpisodeContentManager Content;
        private SpriteBatch Batch;
        private Texture2D _texture = null;
        public String SelectedTexture
        {
            set
            {
                try
                {
                    _texture = Content.GetTexture(value);
                }
                catch (ContentLoadException) { _texture = null; }
                this.Invalidate();
            }
        }

        public void Initialize(Jemgine.Engine.EpisodeContentManager Content)
        {
            this.Content = Content;
        }

        public TexturePreview()
        {
            InitializeComponent();
        }

        protected override void GDCInitialize()
        {
            Batch = new SpriteBatch(GraphicsDevice);
            base.GDCInitialize();
        }




        protected override void GDCDraw()
        {
            try
            {
                GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.Black);
                Batch.Begin();
                if (_texture != null) Batch.Draw(_texture, Vector2.Zero, Microsoft.Xna.Framework.Color.White);
                Batch.End();

                base.GDCDraw();
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.Message);
            }
        }
    }
}
